load("@io_bazel_rules_docker//container:container.bzl", "container_push")
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm//nuxt:index.bzl", "nuxt")

files = ["nuxt.config.js"] + glob([
    "assets/**",
    "components/**/*.vue",
    "layouts/*.vue",
    "middleware/*.js",
    "pages/**/*.vue",
    "plugins/*.js",
    "static/*",
    "store/*.js",
])

deps = [
    "@npm//@nuxtjs/axios",
    "@npm//bootstrap",
    "@npm//bootstrap-vue",
    "@npm//core-js",
    "@npm//dateformat",
    "@npm//electron",
    "@npm//pug",
    "@npm//pug-plain-loader",
    "@npm//sass",
    "@npm//sass-loader",
    "@npm//vue",
    "//nexus/meta_api/js/client",
    "//nexus/views/js",
]

nuxt(
    name = "web-dev",
    args = [
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
        "--watch-poll",
    ],
    data = files + deps,
)

nuxt(
    name = ".nuxt",
    args = [
        "build",
        "--standalone",
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
        "--buildDir=$(@D)",
    ],
    data = files + deps,
    output_dir = True,
)

nodejs_image(
    name = "image",
    base = "//images/production:base-nodejs-image",
    data = glob(["static/*"]) + [
        "nuxt.config.js",
        ":.nuxt",
        "@npm//@nuxtjs/axios",
        "@npm//bootstrap-vue",
        "@npm//nuxt",
    ],
    entry_point = "@npm//:node_modules/nuxt/bin/nuxt.js",
    templated_args = [
        "start",
        "-c",
        "nexus/cognitron/web/nuxt.config.js",
    ],
)


container_push(
    name = "push-public-latest",
    format = "Docker",
    image = ":image",
    registry = "registry.hub.docker.com",
    repository = "thesuperpirate/nexus-cognitron-web",
    tag = "latest",
)

container_push(
    name = "push-public-testing",
    format = "Docker",
    image = ":image",
    registry = "registry.hub.docker.com",
    repository = "thesuperpirate/nexus-cognitron-web",
    tag = "testing",
)

